import java.text.DecimalFormat;

/**
 * Created by nanxin.cnx on 2015/7/11.
 */

/**
 * 占位符说明:
 * 0 一个数字
 * # 一个数字，不包括 0
 * . 小数的分隔符的占位符
 * , 分组分隔符的占位符
 */
public class DecimalFormatTest {
    public static void main(String[] args) {
        DecimalFormat df1 = new DecimalFormat("#.#");
        DecimalFormat df2 = new DecimalFormat("###.###");
        DecimalFormat df3 = new DecimalFormat("0.0");
        DecimalFormat df4 = new DecimalFormat("000.000");

        DecimalFormat df5 = new DecimalFormat("0,0.00");

        double num = 12.34;
        double num2 = 1234.5678;

        System.out.println(df1.format(num));
        System.out.println(df2.format(num));
        System.out.println(df2.format(num2));
        System.out.println(df3.format(num));
        System.out.println(df4.format(num));

        System.out.println(df5.format(num));
    }
}
